package common

import (
	"encoding/json"
	"io/ioutil"
)

//全局单例
var G_conifg *Config

type Config struct {
	ApiPort         string   `json:"apiPort"`
	ApiReadTimeOut  int      `json:"apiReadTimeOut"`
	ApiWriteTimeOut int      `json:"apiWriteTimeOut"`
	EtcdEndpoints   []string `json:"etcdEndpoints"`
	EtcdDialTimeout int      `json:"etcdDialTimeout"`
	WebRoot         string   `josn:"webRoot"`
	MongoUrl        string   `josn:"mongoUrl"`
	MongoTimeOut    int      `josn:"mongoTimeOut"`
}

func InitConfig(fileName string) (err error) {
	//读取文件
	content, err := ioutil.ReadFile(fileName)
	if err != nil {
		return err
	}
	//json序列化
	conf := &Config{}
	if err = json.Unmarshal(content, conf); err != nil {
		return err
	}
	G_conifg = conf
	return
}
